package com.ruoyi.sale.auditStatusMachine.impl;

import com.ruoyi.audit.domain.Audit;
import com.ruoyi.audit.mapper.AuditMapper;
import com.ruoyi.sale.auditStatusMachine.StatusService;
import com.ruoyi.sale.domain.SaleGoodsOrder;
import com.ruoyi.sale.mapper.SaleGoodsMapper;
import org.springframework.stereotype.Component;

/**
 * 销货单 驳回
 * @Author Mr.Yi.Zhang
 * @Version 1.0
 */
@Component
public class Reject implements StatusService {

    private static final String FLAG = "2";
    @Override
    public String get() {
        return FLAG;
    }


    /** 销货单Mapper */
    private SaleGoodsMapper saleGoodsMapper;
    /** 销售审核Mapper */
    private AuditMapper auditMapper;
    public Reject(
            SaleGoodsMapper saleGoodsMapper,
            AuditMapper auditMapper
    ) {
        this.saleGoodsMapper = saleGoodsMapper;
        this.auditMapper = auditMapper;
    }
    @Override
    public int execute(SaleGoodsOrder order) {
        // 同步销售审核状态
        Audit auditQueryParams = new Audit();
        auditQueryParams.setOrderId(order.getSaleorderId());
        auditQueryParams.setOrderType("3");
        Audit audit = auditMapper.selectAuditByOrderId(auditQueryParams);
        audit.setAuditStatus(order.getSaleGoodsStatus());
        auditMapper.updateAudit(audit);

        // 同步销货单状态
        return saleGoodsMapper.auditSale(order);
    }
}
